<?php
	function _show_text($name, $id, $value=null, $class='text', $style=null, $show=true){/*{{{*/
		$html =<<<EOT
		<input class="$class" type="text" name="$name" id="$id" value="$value" style="$style"/>
EOT;
		if ($show) echo $html;
		return $html;
	}/*}}}*/

	function _show_select($name, $id=null, array $value_texts, $c_value=null, $class='', $style=null, $show=true){/*{{{*/
		$html = null;
		$html = "<select name='$name' id='$id' class='$class' style='$style'>";
		foreach($value_texts as $info){
			$val = $info['v'];
			$text = $info['text'];
			
			$checked = null;
			if ($val == $c_value){
				$checked = 'selected="selected"';
			}

			$html .=<<<EOT
				<option value='$val' $checked>$text</option>
EOT;
		}
		$html .= '</select>';
		if ($show) echo $html;
		return $html;
	}/*}}}*/

	function pager($page_total, $cur_page, $url_prefix){/*{{{*/
		if(empty($page_total) || empty($url_prefix)){
			return false;
		}

		$html =<<<EOT
		<span>$cur_page/$page_total</span>
EOT;
		
		if ($cur_page > 1){
			$last_page = $cur_page - 1;
			$html .= <<<EOT
			<a href="{$url_prefix}{$last_page}" title="上一页" ><上一页</a>
EOT;
		}

		if ($cur_page < $page_total){
			$next_page = $cur_page + 1;
			$html .= <<<EOT
			<a href="{$url_prefix}{$next_page}" title="下一页" >下一页></a>
EOT;
		}

		return $html;
	}/*}}}*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html> 
	<head> 
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
		<title>开心赚宝到柜类验证码</title>

		<style type="text/css">
			.clearfix:after{content:'\0020';display:block;height:0;clear:both;}
			body {
				font-size: 12px;
				width: 960px;
				margin: 0 auto;
				background-color:#F9F9F9;
			}
			.readonly {
				color: #6D6D6D;
			}
			.search form input, .search form select {
				margin-top: 10px;
			}
			table {
				width: 100%;
				border-collapse:collapse;
			}
			tr{
				height: 40px;
				border-bottom:1px solid #e3e3e3;
			}
			th, td{
				text-align: center;
			}
			.list {
				margin-top: 20px;
			}
			.list table {
				margin: 10px 0;
			}
			.border {
				border-bottom: 1px solid #E3E3E3;
				padding-bottom: 5px;
			}
			.url {
				font-size: 12px;
			}
			.download {
				margin: 5px 0;
			}
		</style>
	</head>
	<body>
<div class="content clearfix">
	<div class="border clearfix">
	<h3 style="float:left">开心赚宝到柜类中奖用户列表</h3>
	<?php if ($isAdmin) { ?>
	<a style="float:right; margin:18px 0;" href="<?php echo SystemProperties::$app_host;?>">回到管理后台</a>
	<?php } ?>
	</div>
	<div class="search clearfix border">
		<form method="get">
			<h4>搜索</h4>

			<label for="platform">选择平台</label>
			<?php _show_select('platform', 'platform', $platform_select, $platform);?>
			<br/>

			<label for="kw">商品名称</label>
			<input type="text" name="product_kw" id="product_kw" value="<?php echo $product_kw;?>" <?php echo (($isAdmin)?'':'readonly class="readonly"');?> />
			<?php if ($isAdmin && !empty($product_kw)) { ?>
			<label>合作方链接</label>
			<input type="text" onclick="javascript: this.select();" class="url readonly" value="<?php echo $unlogin_url;?>" />
			<label>合作方验证码</label>
			<input type="text" onclick="javascript: this.select();" class="url readonly" value="<?php echo $check_url;?>" />
			<?php } ?>
			<br/>

			<label for="kw">用户名称</label>
			<?php _show_text('user_name', 'user_name', $user_name); ?>

			<label for="status">领取状态</label>
			<?php _show_select('status', 'status', $status_select, $status); ?>
			<br/>

			<?php _show_select('time_type', 'time_type', $time_type_select, $time_type); ?>
			<?php _show_text('start_time', 'start_time', $start_time); ?>
			-
			<?php _show_text('end_time', 'end_time', $end_time); ?>
			
			<input type="submit" value="搜索" />
		</form>
	</div>
	<div class="list border">
		<div class="page">
			<label>共<?php echo $data_total;?>件</label>
			<?php echo pager($total_page, $page, $url_prefix);?>
			<a href="<?php echo $download_url;?>">下载Excel表格</a>
		</div>
		<table>
			<tr>
				<th>中奖时间</th>
				<th>姓名</th>
				<th>用户名</th>
				<th>生日</th>
				<th>电话</th>
				<th>省份</th>
				<th>城市</th>
				<th>地址/邮编</th>
				<th>中奖商品</th>
				<th>验证码</th>
				<th>状态</th>
			</tr>
			
			<?php
			if (!empty($data)){
				foreach($data as $p){
			?>
			<tr>
				<td><?php echo date("m-d H:i", strtotime($p['create_time']));?></td>
				<td><?php echo $p['user_name'];?></td>
				<td><?php echo $p['ht_user_name'];?></td>
				<td><?php echo $p['birthday'];?></td>
				<td><?php echo $p['phone'];?></td>
				<td><?php echo $p['province'];?></td>
				<td><?php echo $p['city'];?></td>
				<td><?php echo $p['address'].'/'.$p['zipcode'];?></td>
				<td><?php echo $p['product_name'];?></td>
				<td><?php echo $p['code'];?></td>
				<td><?php echo $p['status'];?></td>
			</tr>
			<?php
				}
			}
			?>
		</table>
		<div class="page">
			<label>共<?php echo $data_total;?>件</label>
			<?php echo pager($total_page, $page, $url_prefix);?>
		</div>
	</div>
		
</div>
	</body>
</html>
